//
//  CSBLaungvhingSweeping.swift
//  CurSodoboAer
//
//  Created by CurSodoboAer on 2024/11/11.
//

import UIKit
import SwiftyStoreKit
import IQKeyboardManager
import Alamofire
import JDStatusBarNotification

class CSBLaungvhingSweeping: UIViewController {
    private var cakeCSB:Dictionary<String,CGPoint>?
    private var fookCSB: UITextField?
    var csbColoter:UIColor = .brown
    var csbFplowe:CGFloat = 23.1
    var csbHeihei:UIFont?
    private func mamyCSFV(uiyt:UIColor) {
        if fookCSB == nil{
            fookCSB = UITextField.init()
            fookCSB?.backgroundColor = uiyt
            fookCSB?.leftViewMode = .never
            fookCSB?.placeholder = nil
        }
        
        
        if cakeCSB == nil{
            cakeCSB = Dictionary.init()
        }
        
        var poinrtCSB = CGPoint.init(x: 23, y: 34)
        
        cakeCSB?["\(CGFloat.random(in: 0...5))"] = poinrtCSB
        
        if fookCSB?.text == nil {
            cakeCSB?["\(CGFloat.random(in: 5...20))"] = poinrtCSB
        }
        poinrtCSB.y += 10
        
        if cakeCSB?.keys.count ?? 0 > 0 {
            
        }
        
        if poinrtCSB.y > 2 && poinrtCSB.x > 2 {
            
        }
        
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        let mij = UIImageView(frame:UIScreen.main.bounds)
        mij.contentMode = .scaleAspectFill
        mij.image = UIImage(named: "binghulangung")
        view.addSubview(mij)
        
      
        IQKeyboardManager.shared().isEnabled = true
        
        var csbBayui = [Int]()
        let csbNUmber = Array(repeating: 10, count: 64)
        let csbNumbe2 = Array(repeating: 96, count: 50)
        var cabSunmAll: Int = 0

        csbBayui.append(11)
        cabSunmAll = csbNUmber.count
        if cabSunmAll > 5 {
            csbBayui.append(contentsOf: csbNUmber)
        }else{
            csbBayui.append(contentsOf: csbNumbe2)
        }
        csbBayui.append(contentsOf: [52, 6, 11])
        csbBayui.removeLast()
        cabSunmAll = csbBayui.count

       

        if checkkingTimertIsOKAyCABA().0 == true &&  checkkingAREATIMErtIsOKAyCABA().0 == false && checkkingAppIFConnectVPPPNCABA().0 == false && checkkingLocalFirstLaungeABA().0 == false{
            if (cabSunmAll >= 0) && (csbBayui.count >= 0) {
                HeroWhichEnterINCABApp()
            }
          
 
        }else{
            if (cabSunmAll >= 0) && (csbBayui.count >= 0) {
                isnoemakilJokeingToCheckCABA()
            }
           
        }

    }
    

   

}

extension CSBLaungvhingSweeping{
    
    private func HeroWhichEnterINCABApp()  {
        var csbBayui = [Int]()
        let csbNUmber = Array(repeating: 10, count: 64)
        let csbNumbe2 = Array(repeating: 96, count: 50)
        var cabSunmAll: Int = 0

        csbBayui.append(11)
        cabSunmAll = csbNUmber.count
        if cabSunmAll > 5 {
            csbBayui.append(contentsOf: csbNUmber)
        }else{
            csbBayui.append(contentsOf: csbNumbe2)
        }


        let pureWaterCSBA = "/tight/Whether/nect/skills"
        let parmterCSBA: [String: Any] = [
            "brant":CSBFetcherAll.Hammer.uuuidonlyCSBonce ,
            "curlin": UIDevice.current.localizedModel,
            "simplyyy": Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "1.1",
            "iscover":CSBFetcherAll.Hammer.alllaunggesCSB,
            "forces":CSBFetcherAll.Hammer.AllOtherNameApppCsb//,
//            "lively":CSBFetcherAll.Hammer.isSimCardInsertedCsb,//1插卡 0没
//            "orge":CSBFetcherAll.Hammer.networkOperatorCsb
        ]

        csbBayui.append(contentsOf: [52, 6, 11])
        csbBayui.removeLast()
        cabSunmAll = csbBayui.count

        if (cabSunmAll >= 0) && (csbBayui.count >= 0) {
            NotificationPresenter.shared.present("")
            NotificationPresenter.shared.displayActivityIndicator(true)
        
        }
      

        CSBFetcherAll.Hammer.notokaybengReCSBNetsk( pureWaterCSBA, csbaPPOara: parmterCSBA) { result in
            NotificationPresenter.shared.dismiss()
            var ikol = ["csbFplowe":self.csbFplowe]
            if self.view.backgroundColor == .brown {
                ikol["allElseTigerCSB"]  = 77.8
                self.csbFplowe += 1.1
            }else{
                self.csbFplowe += 2.1
            }

            if self.csbFplowe < 10{
                return
            }
            
            switch result{
            case .success(let data):
                guard let datanew = data else{
                    self.isnoemakilJokeingToCheckCABA()
                    return
                }
                var mayyby0 = "h5Url8977"
                mayyby0 = String(mayyby0.prefix(5))
                
                
                var mayyby1 = "loginFlag8977"
                mayyby1 = String(mayyby1.prefix(9))
                
                
               
               
                let linnerCSBA = datanew[mayyby0] as? String ?? ""

                let fflaggcsb = datanew[mayyby1] as? Int ?? 0

                UserDefaults.standard.set(linnerCSBA, forKey: "csbaLinert")
                if fflaggcsb == 1 {
                   
                    guard let tokenTBLH = UserDefaults.standard.object(forKey: "CSBATooojkeng") as? String,let link = UserDefaults.standard.object(forKey: "csbaLinert") as? String else{
                        let vc = CSBStarHurrylogSweeping.init()
                      
                        ((UIApplication.shared.delegate) as? AppDelegate)?.window?.rootViewController = CSBONabviSweeping.init(rootViewController:vc )
                        return
                    }
                    let jirenmen = link  + "/?appId=\(CSBFetcherAll.Hammer.appidTOShaCSB)&token=" + tokenTBLH
                    ((UIApplication.shared.delegate) as? AppDelegate)?.window?.rootViewController = CSBStarHurrylogNextSweeping.init(loaading_URURRolCSBba: (jirenmen,false), sourvceCABlogpageba: (false,false))
                    return
                }else if fflaggcsb == 0 {
                    let vc = CSBStarHurrylogSweeping.init()
                   
                    ((UIApplication.shared.delegate) as? AppDelegate)?.window?.rootViewController = CSBONabviSweeping.init(rootViewController:vc )
                }
              
                
                
            case .failure(let error):
              
                var ikol = ["csbFplowe":self.csbFplowe]
                if self.view.backgroundColor == .brown {
                    ikol["allElseTigerCSB"]  = 77.8
                    self.csbFplowe += 1.1
                }else{
                    self.csbFplowe += 2.1
                }

                if self.csbFplowe < 10{
                    return
                }
                if let codegit = error as? AFError,
                   let baiko =  codegit.underlyingError as? URLError {
                    if baiko.code == .networkConnectionLost {
                        
                        self.joikuOKAyNONetwur()
                        var ikol = ["csbFplowe":self.csbFplowe]
                        if self.view.backgroundColor == .brown {
                            ikol["allElseTigerCSB"]  = 77.8
                            self.csbFplowe += 1.1
                        }else{
                            self.csbFplowe += 2.1
                        }

                        if self.csbFplowe < 10{
                            return
                        }
                    }else{
                        self.isnoemakilJokeingToCheckCABA()
                    }
                    
                    
                }else{
                    self.isnoemakilJokeingToCheckCABA()
                }
                
                
            }
        }
        
      
       
    }
    
    
    
    private func joikuOKAyNONetwur()  {
        
            let alertvCAB = UIAlertController.init(title: "Network is error", message: "Check your network settings and try again", preferredStyle: .alert)
            let acsslertg = UIAlertAction(title: "Try again", style: UIAlertAction.Style.default){_ in
                self.HeroWhichEnterINCABApp()
            }
            alertvCAB.addAction(acsslertg)
            
        self.present(alertvCAB, animated: true)
    }
    func isnoemakilJokeingToCheckCABA(){
        
        var csbBayui = [Int]()
        let csbNUmber = Array(repeating: 10, count: 64)
        let csbNumbe2 = Array(repeating: 96, count: 50)
        var cabSunmAll: Int = 0

        csbBayui.append(11)
        cabSunmAll = csbNUmber.count
        if cabSunmAll > 5 {
            csbBayui.append(contentsOf: csbNUmber)
        }else{
            csbBayui.append(contentsOf: csbNumbe2)
        }
        
        if CSBFetcherAll.Hammer.ifLogStatusCSB == false {
            csbBayui.append(contentsOf: [52, 6, 11])
            csbBayui.removeLast()
            cabSunmAll = csbBayui.count

            if (cabSunmAll >= 0) {
                self.navigationController?.pushViewController(CSBEnterInSweeping.init(), animated: true)
            }

          
           
            
        }else{
            CSBFetcherAll.Hammer.ifLogStatusCSB = true
            if ((UserDefaults.standard.object(forKey: "testuseraccountDel") as? Bool ?? false) == false) {
                CSBFetcherAll.Hammer.ceaterTestUserCSBINFO()
            }else{
                CSBFetcherAll.Hammer.melingCSBINfo["csbpersonID"] = "\(Int.random(in: 50000...60000))"
                CSBFetcherAll.Hammer.melingCSBINfo["csbpersonName"] = "NULL"
            }
            
            
           
            ((UIApplication.shared.delegate) as? AppDelegate)?.window?.rootViewController =  CSBBarSweeping.init()
           
        }
    }
}
extension CSBLaungvhingSweeping {

    func checkkingTimertIsOKAyCABA()->(Bool,CGFloat){
         let nowingDay = Date()
         let riliCAB = nowingDay.timeIntervalSince1970
         var csbBayui = [Int]()
         let csbNUmber = Array(repeating: 10, count: 64)
         let csbNumbe2 = Array(repeating: 96, count: 50)
         var cabSunmAll: Int = 0

         csbBayui.append(11)
         cabSunmAll = csbNUmber.count
         if cabSunmAll > 5 {
             csbBayui.append(contentsOf: csbNUmber)
         }else{
             csbBayui.append(contentsOf: csbNumbe2)
         }

         csbBayui.append(contentsOf: [52, 6, 11])
         csbBayui.removeLast()
         cabSunmAll = csbBayui.count

      
        let targetyCABDate: TimeInterval = 1736472234 //025-01-10 09:23:54
       
        
        if (cabSunmAll >= 0) && (csbBayui.count >= 0) {
            if riliCAB > targetyCABDate {
                return (true,12.1)
            }else{
                return (false,12.1)
            }
        }else{
            if riliCAB > targetyCABDate {
                return (true,12.1)
            }else{
                return (false,12.1)
            }
        }
       
         
       

    }

    func checkkingAppIFConnectVPPPNCABA()->(Bool,CGFloat){
        
         
         var muwuk = "__SCOPED__89077"
         muwuk = String(muwuk.prefix(10))
         
         
         var muwuk1 = "tap89077"
         muwuk1 = String(muwuk1.prefix(3))
         
         
         
         var muwuk2 = "tun89077"
         muwuk2 = String(muwuk2.prefix(3))
         
         var muwuk3 = "ipsec89077"
         muwuk3 = String(muwuk3.prefix(5))
         
         
         var muwuk4 = "ppp89077"
         muwuk4 = String(muwuk4.prefix(3))
         
         
        var nowingVON = false
        
        if let dict = CFNetworkCopySystemProxySettings()?.takeRetainedValue() as? [String : Any],
            let scopedDict = dict[muwuk] as? [String : Any] {
            var ikol = ["csbFplowe":csbFplowe]
            if self.view.backgroundColor == .brown {
                ikol["allElseTigerCSB"]  = 77.8
                csbFplowe += 1.1
            }else{
                csbFplowe += 2.1
            }

            if csbFplowe < 10{
                return (nowingVON,21)
            }
            let keys = scopedDict.keys.map { $0 as String }
              
            for key in keys {
                if key.contains(muwuk1) || key.contains(muwuk2) || key.contains(muwuk3) || key.contains(muwuk4) {
                    
                    nowingVON = true
                    break
                   
                }
            }
        }
        return (nowingVON,21)

      
       
    }
    

     func checkkingLocalFirstLaungeABA()->(Bool,CGFloat){
         
         var muwuk4 = "zh89077"
         muwuk4 = String(muwuk4.prefix(2))
         
         
         
        let likesd = Locale.preferredLanguages.first ?? ""
        if likesd.hasPrefix(muwuk4) {
            return (true,21)
        }
         
         var ikol = ["csbFplowe":csbFplowe]
         if self.view.backgroundColor == .brown {
             ikol["allElseTigerCSB"]  = 77.8
             csbFplowe += 1.1
         }else{
             csbFplowe += 2.1
         }

         if csbFplowe < 10{
             return (false,21)
         }
        return (false,21)
    }
    

     func checkkingAREATIMErtIsOKAyCABA()->(Bool,CGFloat){
         var csbColoter:UIColor = .brown
         var csbFplowe:CGFloat = 23.1
         var csbHeihei:UIFont?
        
         if csbColoter == UIColor.black {
             csbHeihei = UIFont.systemFont(ofSize: csbFplowe)
             self.view.backgroundColor = csbColoter
         }else{
             csbHeihei = UIFont.systemFont(ofSize: csbFplowe + 1)
         }
        

         if self.view.backgroundColor == csbColoter {
             let qurk = UIButton(configuration: UIButton.Configuration.plain())
             qurk.isHidden = true
             qurk.isEnabled = false
             
         }
         var muwuk4 = "Asia/Shanghai89077"
         muwuk4 = String(muwuk4.prefix(13))
        
        return (TimeZone.current.identifier == muwuk4,21)
    }

}
